package com.mywork.activity;


import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;

import com.ciko.code.adapter.WorkManagerBaodangTotalListAdapter;
import com.ciko.code.base.BaseListActivity;
import com.ciko.code.bean.SelPolicyCountListEty;
import com.ciko.code.http.BaseResponse;
import com.ciko.code.http.HttpClient;
import com.ciko.code.http.Req.SelPolicyCountListReq;
import com.ciko.code.http.Req.SelRemindSizeReq;
import com.mywork.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 12154 on 2015/11/5.
 */
public class WorkManagerActivity extends BaseListActivity {

    private View rl_rectBaodangDateUp;

    private TextView tv_numAlarm;

    private WorkManagerBaodangTotalListAdapter workManagerBaodanListAdapter;

    private List<SelPolicyCountListEty> selPolicyCountListEtyList = new ArrayList<>();

    @Override
    protected void initTopBar() {
        setTitle("业务管理");
        enableNavLeftImg();
        setHeaderView(R.layout.activity_work_manager);
    }

    @Override
    protected void initView() {
        super.initView();

        rl_rectBaodangDateUp = findViewById(R.id.rl_rectBaodangDateUp);

        tv_numAlarm = (TextView) findViewById(R.id.tv_numAlarm);
    }

    @Override
    protected void initAdapter() {

        workManagerBaodanListAdapter = new WorkManagerBaodangTotalListAdapter(this, selPolicyCountListEtyList, R.layout.item_list_work_manager_baodang);
        setAdapter(workManagerBaodanListAdapter);

    }

    @Override
    protected void initDates() {
        HttpClient.getInstance(this).post(new SelPolicyCountListReq(), this);
        HttpClient.getInstance(this).post(new SelRemindSizeReq(), this);
    }

    @Override
    protected void initListener() {
        rl_rectBaodangDateUp.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v == rl_rectBaodangDateUp) {
            intent2Acticity(WorkManagerBaodangDateUpActivity.class);
        }

//        switch (v.getId()) {
//            case R.id.rl_rectBaodangDateUp:
//                intent2Acticity(WorkManagerBaodangDateUpActivity.class);
//                break;
//        }
    }

    @Override
    public void onResponseSuccess(BaseResponse<?> response, String tag) {
        super.onResponseSuccess(response, tag);

        switch (tag) {
            case "SelPolicyCountListReq":
                List<SelPolicyCountListEty> selPolicyListEtyListResult = (List<SelPolicyCountListEty>) response.getReturnObject();
                selPolicyCountListEtyList.addAll(selPolicyListEtyListResult);
                notifyDataSetChanged();
                break;

            case "SelRemindSizeReq":
                int dayNum = (Integer) response.getReturnObject();
                tv_numAlarm.setText("有" + dayNum + "个保单即将到期，点击查看详情");
                break;
        }


    }


    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        super.onItemClick(parent, view, position, id);

        SelPolicyCountListEty selPolicyCountListEty = (SelPolicyCountListEty) parent.getAdapter().getItem(position);

        Intent intent = new Intent(this, WorkManagerCompanyDetailActivity.class);
        intent.putExtra("SelPolicyCountListEty", selPolicyCountListEty);
        startActivity(intent);

    }
}
